<?php

/**
 * ajax actions.
 *
 * @package    project_midnight
 * @subpackage ajax
 * @author     AlvaroLara
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ajaxActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('default', 'module');
  }

  public function executeFavIdea(sfWebRequest $request)
  {
    $idea = IdeaPeer::retrieveByPk($request->getParameter('id'));

    if($this->getUser()->isAuthenticated())
    {
      $c = new Criteria();
      $c->add(FavouritePeer::USER_ID,$this->getUser()->getAppUser()->getId());
      $c->add(FavouritePeer::IDEA_ID,$idea->getId());
      $count = FavouritePeer::doCount($c);
      if($count > 0)
      {
        return $this->renderPartial('ajax/fav_success',array('type' => 'error','message' => 'Seems lile you already faved this... '));
      }
      $fav = new Favourite();
      $fav->setUserId($this->getUser()->getAppUser()->getId());
      $idea->addFavourite($fav);
      $rank = ($request->getParameter('check') == 0)?$idea->rankUp():$idea->rankDown();
      return $this->renderPartial('ajax/fav_success',array('type' => 'notice','message' => 'Idea successfully faved! Aint that greate?'));
    }
    return $this->renderPartial('ajax/fav_success',array('type' => 'error','message' => 'You are not registed, if you want to use this. Please register, its free!'));
  }

}
